package com.cet.designapplication.controller;

import com.cet.designapplication.adapter.Login3rdTarget;
import com.cet.designapplication.pojo.BusinessLaunch;
import com.cet.designapplication.pojo.UserInfo;
import com.cet.designapplication.service.EsQueryService;
import com.cet.designapplication.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author NSOC
 */

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private Login3rdTarget login3rdTarget;

    @Autowired
    private EsQueryService esQueryService;

    @PostMapping("/login")
    public String login(String account, String password) {
        return userService.login(account, password);
    }

    @PostMapping("/register")
    public String register(@RequestBody UserInfo userInfo) {
        return userService.register(userInfo);
    }

    @GetMapping("/gitee")
    public String gitee(String code, String state) {
        return login3rdTarget.loginByGitee(code, state);
    }

    @PostMapping("/business/launch")
    public List<BusinessLaunch> filerBusinessLaunch(@RequestParam("city") String city,
                                                    @RequestParam("sex") String sex,
                                                    @RequestParam("product") String product) {
        return userService.filterBusinessLaunch(city, sex, product);
    }

    @PostMapping("/api/post")
    public String post() {
        return "post cors request success!";
    }

    @GetMapping("/api/get")
    public String get() {
        return "get cors request success!";
    }

    @GetMapping("/queryEsBySql")
    public Object queryEsBySql(String querySql, int fetchSize) {
        return esQueryService.queryEsBySql(querySql, fetchSize);
    }
}
